{$CLEO .cs}
{$USE CLEO+}
{$USE ini}

0000: NOP

script_name "Start Interior"

// By ArtemQa146

wait 700

if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
then
    if
        0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
    then
        0AA7: call_function_return 30@ num_params 0 pop 0 29@
        if
            not 29@ >= 0x1020000
        then
            0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the Busy Pedestrians mod is disabled" time 15000
            0AA3: free_dynamic_library 31@
            0A93: terminate_this_custom_script
        end
        0AA3: free_dynamic_library 31@
    end
else
    0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the Busy Pedestrians mod is disabled" time 15000
    0AA3: free_dynamic_library 31@
    0A93: terminate_this_custom_script
end

if
    0E2D: is_game_first_start
then
    0F00: load_special_model_dff "modelsq\Spanner1" txd "modelsq\ImpInt" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Improved interiors.ini" section "Models" key "Spanner"
    0F00: load_special_model_dff "modelsq\Sponge" txd "modelsq\ImpInt" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Improved interiors.ini" section "Models" key "Sponge"
    0F00: load_special_model_dff "modelsq\Broom1" txd "modelsq\ImpInt" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Improved interiors.ini" section "Models" key "Broom"
    0F00: load_special_model_dff "modelsq\HairCLipper" txd "modelsq\ImpInt" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Improved interiors.ini" section "Models" key "HairCLipper"
end

const
    Spanner = 31@
    Sponge = 30@
    Broom = 29@
    hairclipper = 28@
    scr_gym = 27@
    scr_garage = 26@
    scr_chef = 25@
    scr_club = 24@
    scr_barber = 23@
    scr_ammo = 22@
    scr_sex = 21@
    time = 20@
    scr_dance = 19@
    time_inside = 1500
end

0AF0: Spanner = read_int_from_ini_file "cleo\Improved interiors.ini" section "Models" key "Spanner"
0AF0: Sponge = read_int_from_ini_file "cleo\Improved interiors.ini" section "Models" key "Sponge"
0AF0: Broom = read_int_from_ini_file "cleo\Improved interiors.ini" section "Models" key "Broom"
0AF0: hairclipper = read_int_from_ini_file "cleo\Improved interiors.ini" section "Models" key "HairCLipper"

0AF0: scr_gym = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "GYM"
0AF0: scr_garage = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Garage"
0AF0: scr_chef = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Chef"
0AF0: scr_club = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Club"
0AF0: scr_barber = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Barber"
0AF0: scr_ammo = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "AmmuNation"
0AF0: scr_sex = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Sex Shop"
0AF0: scr_dance = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Improved interiors" key "Dance"

time = 0

while true
wait time
    if
        player.Defined(0)
    then
    //0AD1: show_formatted_text_highpriority "%d" time 2000 $ACTIVE_INTERIOR

        if
            $ACTIVE_INTERIOR == 0
        then
            time = 0
            continue
        end
        
        // shopping basket
        if
            $ONMISSION == 0
        then
            077E: get_active_interior_to 1@
            if or
                1@ == 6
                1@ == 4
                1@ == 18
            then

                if or
                    0EEA: locate_char_distance_to_coordinates $player_actor pos -27.8786 -81.1702 1003.5469 radius 30.0
                    0EEA: locate_char_distance_to_coordinates $player_actor pos -28.2176 -51.7941 1003.5469 radius 30.0
                    0EEA: locate_char_distance_to_coordinates $player_actor pos -30.9906 -14.84 1003.5573 radius 30.0
                then
                    0AAA: 1@ = get_script_struct_named "BASKSH"
                    if
                        1@ == 0
                    then
                        0A92: stream_custom_script "Shopping Basket.qa"
                        wait 2000
                    end
                end
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'ATRIUMQ'
        if and
            1@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 1721.7184 -1656.9252 20.9741 radius 60.0
                $ACTIVE_INTERIOR == 18
            then
                0A92: stream_custom_script "Atrium.qa"
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'SexSell'
        if and
            1@ == 0
            $ONMISSION == 0
            scr_sex == 1
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos -104.3625 -17.7231 1000.7187 radius 50.0
                $ACTIVE_INTERIOR == 3
            then
                0A92: stream_custom_script "Sex Seller.qa"
                wait 1000
                time = time_inside
                continue
            end
        end

        
        0AAA: 1@ = get_script_struct_named 'INTREQ1'
        0AAA: 2@ = get_script_struct_named 'EHIFIXD'
        if and
            1@ == 0
            not 2@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 443.9658 -86.0221 999.5547 radius 60.0
                $ACTIVE_INTERIOR == 4
            then
                0A92: stream_custom_script "Interior RestQa.qa" Broom Sponge
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'INTREQ2'
        0AAA: 2@ = get_script_struct_named 'EHIFIXD'
        if and
            1@ == 0
            not 2@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 452.2912 -106.9859 999.5547 radius 60.0
                $ACTIVE_INTERIOR == 5
            then
                0A92: stream_custom_script "Interior RestQa2.qa" Broom
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'INTREQ3'
        0AAA: 2@ = get_script_struct_named 'EHIFIXD'
        if and
            1@ == 0
            not 2@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 446.4689 -13.2373 1000.7344 radius 50.0
                $ACTIVE_INTERIOR == 1
            then
                0A92: stream_custom_script "Interior RestQa3.qa" 
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'INTREQ4'
        0AAA: 2@ = get_script_struct_named 'EHIFIXD'
        if and
            1@ == 0
            not 2@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 443.1088 -62.0085 1000.1406 radius 50.0
                $ACTIVE_INTERIOR == 6
            then
                0A92: stream_custom_script "Interior RestQa4.qa" Broom
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'INTSXQ1'
        0AAA: 3@ = get_script_struct_named 'SEXSEL2'
        0AAA: 2@ = get_script_struct_named 'EHIFIXD'
        if and
            1@ == 0
            3@ == 0
            not 2@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 745.3214 1442.0612 1102.7266 radius 50.0
                $ACTIVE_INTERIOR == 6
            then
                0A92: stream_custom_script "Interior SexQa.qa"
                0A92: stream_custom_script "Sex Seller 2.qa"
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'INTPDQ1'
        0AAA: 2@ = get_script_struct_named 'EHIFIXD'
        if and
            1@ == 0
            not 2@ == 0
            $ONMISSION == 0
        then
            if and
                locate_char_distance_to_coordinates $player_actor pos 323.102 311.317 999.1562 radius 50.0
                $ACTIVE_INTERIOR == 5
            then
                0A92: stream_custom_script "Interior Police.qa"
                wait 1000
                time = time_inside
                continue
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'ImGYMQ'
        if and
            scr_gym == 1
            1@ == 0
        then
            0AAA: 2@ = get_script_struct_named 'GYMSF'
            0AAA: 3@ = get_script_struct_named 'GYMLS'
            0AAA: 4@ = get_script_struct_named 'GYMLV'
            if or
                2@ > 0
                3@ > 0
                4@ > 0
            then
                if
                    not $ACTIVE_INTERIOR == 0
                then
                    0A92: stream_custom_script "Improved GYM.qa"
                    wait 1000
                    time = time_inside
                    continue
                end
            end
        end
        
        
        0AAA: 1@ = get_script_struct_named 'ImGARQ'
        if and
            scr_garage == 1
            1@ == 0
        then
            0AAA: 1@ = get_script_struct_named 'CARMOD'
            if
                1@ > 0
            then
                if or
                    $ACTIVE_INTERIOR == 1
                    $ACTIVE_INTERIOR == 2
                    $ACTIVE_INTERIOR == 3
                then
                    0A92: stream_custom_script "Improved Garages.qa"
                    wait 1000
                    time = time_inside
                    continue
                end
            end
        end
        
        
        0AAA: 1@ = get_script_struct_named 'ChefQa'
        0AAA: 2@ = get_script_struct_named 'WshIQa'
        if and
            scr_chef == 1
            1@ == 0
            2@ == 0
        then
            0AAA: 1@ = get_script_struct_named 'JFUD'
            if
                1@ > 0
            then
                if
                    not $ACTIVE_INTERIOR == 0
                then
                    0A92: stream_custom_script "ChefQa.qa"
                    if
                        $ONMISSION == 0
                    then
                        0A92: stream_custom_script "CleanerQ.qa" Broom
                    end
                    wait 1000
                    time = time_inside
                    continue
                end
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'AmmoQa'
        if and
            scr_ammo == 1
            1@ == 0
        then
            0AAA: 1@ = get_script_struct_named 'AMUNAT'
            if
                1@ > 0
            then
                if
                    not $ACTIVE_INTERIOR == 0
                then
                    0A92: stream_custom_script "AmmoQa.qa"
                    wait 1000
                    time = time_inside
                    continue
                end
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'ImClub'
        if and
            scr_club == 1
            1@ == 0
        then
            0AAA: 1@ = get_script_struct_named 'STRIPW'
            0AAA: 2@ = get_script_struct_named 'BAR'
            if or
                1@ > 0
                2@ > 0
            then
                0AAA: 1@ = get_script_struct_named 'GFDATE'
                if and
                    1@ == 0
                    $ONMISSION == 0
                    not $ACTIVE_INTERIOR == 0
                then
                    0A92: stream_custom_script "Improved Club.qa" Spanner Sponge Broom
                    if
                        scr_dance == 1
                    then
                        0A92: stream_custom_script "Improved Dance.qa"
                    end
                    wait 1000
                    time = time_inside
                    continue
                end
            end
        end
        
        0AAA: 1@ = get_script_struct_named 'ImBarb'
        0AAA: 2@ = get_script_struct_named 'ImprB2'
        if or
            1@ == 0
            2@ == 0
        then
            0AAA: 1@ = get_script_struct_named 'BARB'
            if and
                scr_barber == 1
                1@ > 0
                056D:   actor $9731 defined
            then
                0AAA: 1@ = get_script_struct_named 'ImBarb'
                if and
                    1@ == 0
                    not $ACTIVE_INTERIOR == 0
                then
                    0A92: stream_custom_script "Improved Barber.qa" hairclipper
                end
                0AAA: 1@ = get_script_struct_named 'ImprB2'
                if and
                    1@ == 0
                    not $ACTIVE_INTERIOR == 0
                then
                    0A92: stream_custom_script "ImprB2.qa"
                end
                wait 2000
                time = time_inside
                continue
            end
        end
        
        
        
    end
end